package com.tcm.portal.web.controller;

import com.base.core.utils.R;
import com.tcm.core.service.DepartmentService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/portal")
@RestController
public class DepartmentController {

    @DubboReference(version = "0.0.1-alpha", check = false, timeout = 3000)
    private DepartmentService departmentService;

    /**
     * 获取部门信息
     * @param id
     * @return
     * @throws Exception
     */
    @GetMapping("/department/view")
    public R view(@RequestParam("id") Long id) throws Exception {
       return R.success(departmentService.findById(id));
    }

    /**
     * 获得树形结构数据
     * @return
     * @throws Exception
     */
    @GetMapping("/department/tree")
    public R tree() throws Exception{
        return R.success(departmentService.listToTree());
    }

    /**
     * 查询某科室下所有子科室
     * @param id
     * @return
     */
    @GetMapping("/department/subtree")
    public R treeById(@RequestParam("id") Long id) throws Exception {
        return R.success(departmentService.listSubDepartment(id));
    }

}